package com.dts.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ConcurrentHashMap;

public class Server {
    public static ConcurrentHashMap<String ,ClientHandler> clientMap =  new ConcurrentHashMap<>();

    public static void main(String[] args){
        int port = 8888;
        try (ServerSocket serverSocket = new ServerSocket(port)) {
            System.out.println("服务器启动，等待连接...");
            while (true) {
                Socket socket = serverSocket.accept();
                System.out.println(socket.getInetAddress().getHostAddress()+":"+socket.getPort()+"上线了!!!欢迎!!");
                ClientHandler  handler = new ClientHandler(socket);
                clientMap.put(socket.getInetAddress().getHostAddress()+":"+socket.getPort(),handler);
                new Thread(handler).start();
            }
        } catch (IOException e) {
            System.err.println("服务器异常: " + e.getMessage());
        }
    }
}
